<%-- 
    Document   : listAnnonce
    Created on : Jun 15, 2013, 4:17:47 PM
    Author     : Anna SAELEE
--%>

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link type="text/css" rel="stylesheet" href="style.css"/>
        <title>List des nouvelles</title>
    </head>
    <%  Connection conn;
        Statement stmt;
        ResultSet rs;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dormitorymanagement", "root", "root");
            stmt = conn.createStatement();%>
    <body>
        <div class="wrapper">
            <div class="header"></div>
            <div class="navigator"> <a href="#">MENU</a> > <a href="#">SUBMENU</a> 30*1000 </div>
            <div class="workspace">
                <%@include file="connect.jsp" %>
                <div class="workspace2">
                    <h3>List des nouvelles</h3><br/>
                    <%
                        if (session.getAttribute("username") == null || !session.getAttribute("username").equals("admin")) {%>
                    Connectez-vous comme l'administrator, s'il vous plaît
                    <% } else if (session.getAttribute("username").equals("admin")) {%>
                    <table width="100%" border="1">
                        <tr style="text-align: center">
                            <th>Date</th>
                            <th>Catégorie</th>
                            <th>Sujet</th>
                            <th colspan="2">Gérer</th>
                        </tr>
                        <% String sql = "SELECT nid, date ,cname, subject FROM news LEFT JOIN category ON news.cid=category.cid";
                            rs = stmt.executeQuery(sql);
                            while (rs.next()) {
                                String nid = rs.getString("nid");
                        %>
                        <tr style="text-align: center">
                            <td style="text-align: center"><%= rs.getString("date")%></td>
                            <td><%= rs.getString("cname")%></td>
                            <td><%= rs.getString("subject")%></td>
                            <td>
                                <form method="post" action="modifyAnnonce.jsp" name="modifyNews">
                                    <input type="hidden" name="newsID" value="<%= nid%>"/>
                                    <input type="submit" name="modify" value="Modifier"/>
                                </form>
                            </td>
                            <td>
                                <form method="post" action="Delete" name="deleteNews">
                                    <input type="hidden" name="typeMss" value="deleteNews"/>
                                    <input type="hidden" name="nid" value="<%= nid%>"/>
                                    <input type="submit" name="delete" value="Supprimer"/>
                                </form>
                            </td>
                        </tr> 
                        <% }%>
                    </table>
                    <% }%>
                </div>
                <%@include file="sidespace.jsp" %>
            </div>
            <div class="footer"> FOOTER 80*1000 </div>
        </div>
    </body>
    <% } finally {
            out.close();
        }
    %>
</html>